﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using umbraco.MacroEngines;
using umbraco.MacroEngines.Library;

namespace uComponents.RazorModels.XPathCheckBoxList
{
    [RazorDataTypeModel("d2d46927-f4f8-4b1b-add7-661cc09a0539")]
    public class XPathCheckBoxListModelBinder2 : IRazorDataTypeModel
    {
        public bool Init(int CurrentNodeId, string PropertyData, out object instance)
        {
            var nodeIds = Helper.CouldItBeXml(PropertyData) ? Helper.GetXmlIds(PropertyData) : Helper.GetCsvIds(PropertyData);
            var library = new RazorLibraryCore(null);

            instance = (library.NodesById(nodeIds.ToList()) as DynamicNodeList);

            return true;
        }
    }
}
